function LoadGame()
{
  	//Background Images
	//menuBg = loadImg('Menu.png','menuBg');
	//phase1Bg = loadImg('Phase1.png','phase1Bg');
	//phase2Bg = loadImg('Phase2.png','phase2Bg');
	
	//stage.addChild(TestBg);
	//stage.addChild(dbgCont);
	//stage.addChild(b1);
}

function loadImg(src,name)
{
	//console.log("Loading "+src);
	var img = new Image();
	img.src = src;
	img.name = name;
	img.loadGfx;
	return new Bitmap(img);

}

/* MENU */
function LoadMenu()
{
	if(currentPhase != 'Menu')
	{
		console.log("Loading Menu");
		
		//On change les Backgrounds
		CleanUp();
		boutonJouer = loadImg('Graph/Menu/menu_play.png','Play');
		sceneMenu.addChild(boutonJouer);
		boutonJouer.onPress=LoadPhase1;

		boutonJouer.setWidth(screenWidth);
		boutonJouer.setHeight(screenWidth/5);
		boutonJouer.y = screenHeight/2 - screenWidth/10;
		stage.addChild(sceneMenu);

		stage.update();
		currentPhase = 'Menu';
		console.log("Menu Loaded");
	}
	else
	{

		console.log("Already in Menu");
	}
}

function LoadPhase1()
{
	if(currentPhase != 'Phase 1')
	{
		console.log("Loading Phase 1");
		CleanUp();
		stage.addChild(sceneP1);

		//Arene
		arene = loadImg('Graph/Arene/arene.png','arene');
		arene.setWidth(screenWidth);
		arene.setHeight(screenHeight);
		sceneP1.addChild(arene);



	  	//Rail
	  	railFixe = loadImg('Graph/Rail/rail_fixe.png','railfixe');
	  	railFixe.setWidth(screenWidth);
	  	railFixe.setHeight(screenWidth/(777/156));
	  	railFixe.y = screenHeight/2 - (screenWidth/(777/156))/2;
	  	//railfixe.y = screenHeight/2;

	  	railMobile1 = loadImg('Graph/Rail/rail_mobile.png','railmob1');
	  	railMobile1.y = screenHeight/2  - (screenWidth/(777/156))/2;
	  	railMobile1.x = 0;
	  	railMobile1.setHeight(screenWidth/(777/156));
	  	railMobile1.setWidth(screenWidth);

	  	railMobile2 = loadImg('Graph/Rail/rail_mobile.png','railmob2');
	  	railMobile2.y = screenHeight/2 - (screenWidth/(777/156))/2;
	  	railMobile2.x = screenWidth;
	  	railMobile2.setHeight(screenWidth/(777/156));
	  	railMobile2.setWidth(screenWidth);

	  	//railMobile1, railMobile2
	  	sceneP1.addChild(railFixe,railMobile1,railMobile2);
	  	


	  	//BOT
	  	b1 = loadImg('Graph/Mecha/mecha01_idle.png','b1');
	  	b2 = loadImg('Graph/Mecha/mecha02_idle.png','b2');

	  	sceneP1.addChild(b1);
	  	sceneP1.addChild(b2);

		bot1 = new Robot(0,b1,100);
		bot2 = new Robot(1,b2,100);
		

		//Bouton round1/ready
		boutonRound1 = loadImg('Graph/Menu/menu_round1.png','Round1');
		boutonRound1.setWidth(screenWidth);
		boutonRound1.setHeight(screenWidth/5);
		boutonRound1.y=screenHeight/2 - screenWidth/10;
		sceneP1.addChild(boutonRound1);
		
		boutonReady = loadImg('Graph/Menu/menu_ready.png','Ready');
		boutonReady.setWidth(screenWidth);
		boutonReady.setHeight(screenWidth/5);
		boutonReady.y=screenHeight/2 + screenWidth/10;

		boutonReady.onPress = function (){sceneP1.removeChild(boutonReady,boutonRound1); stage.update(); LoadPhase2();};
		sceneP1.addChild(boutonReady);
		
	 	//b1.onPress = instantiateBullet.call(bot1,0,1);

		stage.update();
		currentPhase = 'Phase 1';
	}
	else
	{

		console.log("Already in Phase 1");
	}
}


function LoadPhase2()
{
	if(currentPhase != 'Phase 2')
	{
		console.log("Loading Phase 2");
		CleanUp();
		stage.addChild(sceneP2);
		
		sceneP2.addChild(arene);

		//Bouton round2/ready -A tester-
		boutonRound2 = loadImg('Graph/Menu/menu_round2.png','Round2');
		boutonRound2.setWidth(screenWidth);
		boutonRound2.setHeight(screenWidth/5);
		boutonRound2.y=screenHeight/2 - screenWidth/10;
		sceneP2.addChild(boutonRound2);
		
		boutonReady = loadImg('Graph/Menu/menu_ready.png','Ready');
		boutonReady.setWidth(screenWidth);
		boutonReady.setHeight(screenWidth/5);
		boutonReady.y=screenHeight/2 + screenWidth/10;
		boutonReady.onPress = function () {sceneP2.removeChild(boutonReady,boutonRound2);stage.update();};
		sceneP2.addChild(boutonReady);
		
		sceneP2.addChild(b1);
	  	sceneP2.addChild(b2);

		//b1.onPress = function(){ instantiateBullet(2,0); };
		b1.onPress = function(){ sceneP2.addChild(refBullets[2]);};
	  	b2.onPress = function(){ bot2.shoot(); };

		//Bullets
		refBullets[0] = new Image();
		refBullets[0].src = 'Graph/Atks/atk_mech.png';
		refBullets[1] = new Image();
		refBullets[1].src = 'Graph/Atks/atk_elec.png';
		refBullets[2] = new Image();
		refBullets[2].src = 'Graph/Atks/atk_mag.png';

		refBullets[3] = new Image();
		refBullets[3].src = 'Graph/Atks/atk_mech_2.png';
		refBullets[4] = new Image();
		refBullets[4].src = 'Graph/Atks/atk_elec_2.png';
		refBullets[5] = new Image();
		refBullets[5].src = 'Graph/Atks/atk_mag_2.png';
		
	
		sceneP2.addChild(bulletsImg);

		//Boutons atk
	
		atkMech1 = loadImg('Graph/BtnsAtk/AtkMechBtn.png','abmc');
		atkMech1.x = screenWidth - screenWidth*0.20;
		atkMech1.y = screenHeight*0.15;
		atkMech1.onPress = function(){bot1.atkType = 0;};
		
		atkElec1 = loadImg('Graph/BtnsAtk/AtkElecBtn.png','abe');
		atkElec1.x = screenWidth - screenWidth*0.35;
		atkElec1.y = screenHeight*0.15;
		atkElec1.onPress = function(){bot1.atkType = 1;};

		atkMag1 = loadImg('Graph/BtnsAtk/AtkMagBtn.png','abm');
		atkMag1.y = screenHeight*0.05;
		atkMag1.x = screenWidth - screenWidth*0.27;
		atkMag1.onPress = function(){bot1.atkType = 2;};

		sceneP2.addChild(atkMag1,atkMech1,atkElec1);
		

		atkMech2 = loadImg('Graph/BtnsAtk/AtkMechBtn2.png','abmc2');
		atkMech2.x = screenWidth*0.05;
		atkMech2.y = screenHeight - screenHeight*0.25;
		atkMech2.onPress = function(){bot2.atkType = 0; console.log(bot2.atkType); };

		atkElec2 = loadImg('Graph/BtnsAtk/AtkElecBtn2.png','abe2');
		atkElec2.x = screenWidth*0.20;
		atkElec2.y = screenHeight -  screenHeight*0.25;
		atkElec2.onPress = function(){bot2.atkType = 1;};

		atkMag2 = loadImg('Graph/BtnsAtk/AtkMagBtn2.png','abm2');
		atkMag2.x =  screenWidth*0.12;
		atkMag2.y = screenHeight - screenHeight*0.15;
		atkMag2.onPress = function(){bot2.atkType = 2;};

		sceneP2.addChild(atkMag2,atkMech2,atkElec2);
		
		stage.update();

		currentPhase = 'Phase 2';
	}
	else
	{

		console.log("Already in Phase 2");
	}
}


function CleanUp()
{

	stage.removeChild(sceneMenu);
	stage.removeChild(sceneP1);
	stage.removeChild(sceneP2);


}